import axios, { AxiosResponse } from "axios";
import { KindModel } from "../models/Kind";

class KindApis {
    queryKind(): Promise<Array<KindModel>> {
        let promise: Promise<Array<KindModel>> = new Promise((resolve, reject) => {
            axios.get(`/api/kind/kind`)
                .then((result: AxiosResponse) => {
                    let kindArr: Array<KindModel> = result.data.data;
                    resolve(kindArr);
                })
                .catch((error) => {
                    reject(error);
                })
        })
        return promise;
    }

    querySingleKind(): Promise<KindModel> {
        let promise: Promise<KindModel> = new Promise((resolve, reject) => {
            axios.get(`/api/kind/kind`)
                .then((result: AxiosResponse) => {
                    let kind: KindModel = result.data.data;
                    resolve(kind);
                })
                .catch((error) => {
                    reject(error);
                })
        })
        return promise;
    }
}

export const kindApis: KindApis = new KindApis();